package org.example.service.impl;

import org.example.mapper.StockMarketIndexInfoMapper;
import org.example.domain.vo.InnerMarketDomainVo;
import org.example.domain.vo.StockInfoVo;
import org.example.service.StockService;
import org.example.utils.Response;
import org.joda.time.DateTime;
import org.joda.time.format.DateTimeFormat;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class StockServiceImpl implements StockService {
    private final StockInfoVo stockInfo;
    private final StockMarketIndexInfoMapper stockMarketIndexInfoMapper;

    public StockServiceImpl(StockInfoVo stockInfo, StockMarketIndexInfoMapper stockMarketIndexInfoMapper) {
        this.stockInfo = stockInfo;
        this.stockMarketIndexInfoMapper = stockMarketIndexInfoMapper;
    }

    @Override
    public Response<List<InnerMarketDomainVo>> getInnerMarketInfo() {
//        Date nowDate = DateTimeUtil.getLastDate4Stock(DateTime.now()).toDate();
        Date date = DateTime.parse("2021-12-28 09:31:00", DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss")).toDate();
        List<String> innersCode = stockInfo.getInner();
        List<InnerMarketDomainVo> data = stockMarketIndexInfoMapper.getMarketInfo(date, innersCode);
        return Response.success(data);
    }
}
